package com.tanhua.app.controller;

import com.tanhua.app.service.CommentService;
import com.tanhua.model.vo.CommentVo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RequestMapping("/comments")
@RestController
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     * 评论-提交
     */
    @PostMapping
    public ResponseEntity saveComment(@RequestBody Map<String, String> map) {
        // 解析参数
        String movementId = map.get("movementId");
        String comment = map.get("comment");
        // 执行方法
        commentService.saveComment(movementId, comment);

        return ResponseEntity.ok(null);
    }

    /**
     * 评论列表
     */
    @GetMapping
    public ResponseEntity<PageResult<CommentVo>> findPageComment(@RequestParam(defaultValue = "1", required = false) Integer page,
                                          @RequestParam(defaultValue = "10", required = false) Integer pagesize,
                                          String movementId) {
        PageResult<CommentVo> pageResult = commentService.findPageComment(page, pagesize, movementId);

        return ResponseEntity.ok(pageResult);
    }

}
